﻿using System.Collections.Generic;

namespace Vk.Exceptions
{
    /// <summary>
    /// Information about Vkontakte API error
    /// </summary>
    public struct ApiError
    {
        public ApiError(ApiNode rootNode)
        {
            Code = rootNode.Int("error_code");
            Description = rootNode.String("error_description");

            RequestParameters = new Dictionary<string, string>();
            foreach (var node in rootNode.SelectNode("request_params").ChildNodes)
            {
                RequestParameters.Add(node.String("key"), node.String("value"));
            }
        }

        /// <summary>
        /// Error code
        /// </summary>
        public int? Code { get; set; }

        /// <summary>
        /// Description of the error
        /// </summary>
        public string Description { get; set; }

        /// <summary>
        /// Parameters sended to the server
        /// </summary>
        public Dictionary<string, string> RequestParameters { get; set; }
    }
}